package leetcode;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/25 18:59
 * @描述 暂无
 */
public class ListNodeBM9 {
    public static ListNode find(ListNode head, int n){
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode first = dummy;
        ListNode second = dummy;
        // Advances first pointer so that the gap between first and second is n nodes apart
        for (int i = 1; i <= n + 1; i++) {
            if(first!=null){
                first = first.next;
            }else {
                return null;
            }
        }
        // Move first to the end, maintaining the gap
        while (first != null) {
            first = first.next;
            second = second.next;
        }
        second.next = second.next.next;
        return dummy.next;
    }
}
